<template>
  <footer>
    <div class="blank-60h"></div>
    <div class="footer-btn">
        <div class="col-xs-6" id="clearance" v-if="userCode == clientId && groupStatue == 1"  @click.stop.prevent="clearanceModal">一键清仓</div>
        <div class="col-xs-6" id="simubuy" v-if="userCode == clientId && groupStatue == 1"  @click.stop.prevent="toBuy">
          <i class="iconfont icon-mairu"></i>
          模拟买入
        </div>
        <div class="col-xs-12" id="simubuy_empty" v-if="groupStatue != 1"  @click.stop.prevent="toBuy">
          <i class="iconfont icon-mairu"></i>
          模拟买入
        </div>
        <div class="col-xs-6" id="zan" v-if="userCode!= clientId" @click.stop.prevent="like">
          <i class="iconfont icon-zan" v-if="!isPoint"></i><span v-if="!isPoint">赞</span>
          <i class="iconfont icon-dianzan" v-if="isPoint"></i><span v-if="isPoint">取消赞</span>
        </div>
        <div class="col-xs-6" id="toushi" v-if="userCode!= clientId" @click="learnGroup">
          <i class="iconfont icon-toushi" ref="touu"></i>偷师
        </div>
      </div>
  </footer>
</template>

<script>
  import Constant from 'common/constant'
  import RemoteDAO from 'common/remoteDAO'
  import CommonUtil from 'common/common.util'
  import LocalDAO from 'common/localDAO'

  export default {
    name: 'FootBtn',
    data () {
      return {
        isPoint:false,
        testData: false,
      }
    },
    props: {
      userCode: {type: String},
      clientId: {type: String},
      groupStatue: {type: Number},
      groupId: {type: String},
      groupName: {type: String},
      isLogin: {type: Boolean}
    },
    created: function () {
      this.isLike();
    },
    methods: {
      isLike(){
        var self = this;
        if (!self.isLogin) {
          return;
        }
        RemoteDAO.callUC12008309(self.clientId, "1", "1", "2", "3", "1", self.groupId, self.userCode, "1", function (response) {
          if(response.error == 0 ){
            if(response.data.body.length!=0 ){
              _.each(response.data.body,function(user,index){
                if(user.USER_CODE == self.userCode){
                  self.isPoint = true;
                  return false;
                }
              });
            }
          }else{
            this.$store.dispatch('setTip', {text:response.data});
          }
        });
      },
      like(){
        var self = this;
        if (!self.isLogin) {
          self.$store.dispatch('setTip', {text:"请先注册登录"});
          return;
        }
        var actionType = "00";
        if (self.isPoint) {
          actionType = "02";
        }

        var params = {
          userCode:self.userCode,
          actionType:actionType,
          businType:'NRNG',
          communityType:'2',
          objectType:'3',
          relationUserCode:self.clientId,
          relationUserName:self.$store.state.group_nickname,
          beginDate:"",
          endDate:"",
          communityContent:"",
          topicCode:self.groupId,
          topicName:self.groupName,
          serialNo:''
        };
        //点赞接口,社交管理
        RemoteDAO.callUC12008306(params,function (response) {
          if (response.error == 0) {
            self.isPoint = !self.isPoint;
          }else{
            self.$store.dispatch('setTip', {text:response.data});
          }
        });
      },
      toBuy(){
        this.$router.push({path: '/trade/buyin', query: {groupId: this.groupId,menuId:'1'}});
      },
      clearanceModal(){
        this.$store.dispatch('setModal', {visible: true, modalId: 'groupClearanceModal', groupId: this.groupId});
      },
      learnGroup(){
        var self = this
        if (!self.isLogin) {
          self.$store.dispatch('setTip', {text:"请先注册登录"});
          return;
        }
        var nickname = self.$store.state.group_nickname;
        //今日偷师次数查询
        RemoteDAO.callJCL11160(self.userCode,function(response){
          if(response.error == 0 && response.data.body.count <2){
            self.$router.push({
              path: '/learngroup',
              query: {clientId: self.clientId, groupId: self.groupId, groupName:self.groupName, nickname: nickname}
            })
          }else if(response.error == 0 && response.data.body.count >=2){
            self.$store.dispatch('setModal', {visible: true, modalId: 'groupLearnTwoModal'});
          }else{
            self.$store.dispatch('setTip',{text:response.data})
          }
        });
      }
    }
  }
</script>

<style scoped>

</style>
